package com.dzl.util;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

/**
 * Page对象
 *
 * @author wangchao
 * @date 2022/02/15 14:38
 */
@ApiModel(value = "Page对象", description = "Page对象")
@Data
@NoArgsConstructor
public class PageUtils<T> {
	/**
	 * 数据列表
	 */
	@ApiModelProperty(value = "数据列表")
	private List<T> data;
	/**
	 * 各状态下数量
	 */
	@ApiModelProperty(value = "各状态下数量")
	private Map pageCount;
	/**
	 * 总数
	 */
	@ApiModelProperty(value = "总数")
	private Long count;
	/**
	 * 返回信息
	 */
	@ApiModelProperty(value = "返回信息")
	private String msg;
	/**
	 * 返回信息码
	 */
	@ApiModelProperty(value = "返回信息码")
	private Integer code;

	public PageUtils(PageInfo<T> pageInfo) {
		if (!EmptyUtils.isEmpty(pageInfo)) {
			this.data = pageInfo.getList();
			this.count = pageInfo.getTotal();
		}
		this.msg = HttpCode.SUCCESS.getMsg();
		this.code = HttpCode.SUCCESS.getCode();
	}
}
